﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using RL.ObjectLayer;
using RL.BusinessLayer;

namespace RL.SMR
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["Mode"] != null)
            {
                Session.Clear();
            }

            this.lblError.Text = string.Empty;
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            try
            {
                string userName = null;
                string password = null;
                userName = UserName.Text;
                password = Password.Text;
                UserOL b = new UserOL();
                b.UserName = userName;
                b.Password = password;
                SMRSession i = new SMRSession();
                UserBL user = new UserBL();
                i.User = user.GetUser(b);
                if (i.User != null && i.User.UserID != 0)
                {
                    Response.Redirect("Default.aspx", false);
                }

                else
                {
                    throw new Exception("The user name or password provided is incorrect.");
                }
            }
            catch (Exception ex)
            {
                this.lblError.Text = ex.Message;
            }
        }
    }
}